﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Umbraco.Cms.Web.EmbeddedViewEngine;
using Umbraco.Cms.Web.Model.BackOffice;
using Umbraco.Cms.Web.Model.BackOffice.PropertyEditors;

namespace Umbraco.Cms.Web.PropertyEditors.TreeMultiNodePicker
{
	[EmbeddedView("Umbraco.Cms.Web.PropertyEditors.TreeMultiNodePicker.Views.TreeMultiNodePickerEditor.cshtml", "Umbraco.Cms.Web.PropertyEditors")]
	public class TreeMultiNodePickerEditorModel : EditorModel
    {
        [ShowLabel(false)]
		public IList<string> Value { get; set; }

		[ScaffoldColumn(false)]
		[ReadOnly(true)]
		public TreeRenderModel TreeRenderModel { get; set; }

		public override IDictionary<string, object> GetSerializedValue()
		{
			var dic = new Dictionary<string, object>();

			foreach (var item in this.Value)
			{
				dic.Add(global::System.Guid.NewGuid().ToString(), item);
			}

			return dic;
		}

		public override void SetModelValues(IDictionary<string, object> serializedVal)
		{
			this.Value = new List<string>();

			foreach (var item in serializedVal)
			{
				this.Value.Add(item.Value.ToString());
			}
		}

    }
}
